using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using Entidades;
public partial class ABMRecomendacion : System.Web.UI.Page
{
	protected void Page_Load(object sender, System.EventArgs e)
	{
		if (!Page.IsPostBack) {
			preparaAlta();
		}
	}
	protected void linkRecomendacion_Click(object sender, System.EventArgs e)
	{
		traerTodos();
	}
	private void traerTodos()
	{
		try {
			grdRecomendacion.DataSource = Recomendacion.TraerTodos();
			grdRecomendacion.DataBind();
		} catch (Exception ex) {
			grdRecomendacion.DataSource = null;
			grdRecomendacion.DataBind();
			LUM.lum.mensaje(ex.Message);
		}
	}
	protected void linkAceptar_Click(object sender, System.EventArgs e)
	{
		try {
			Recomendacion recomendacion = new Recomendacion();
			recomendacion.IdPostulacion = int.Parse( txtIdPostulacion.Text.ToString());
			recomendacion.IdUsuario = int.Parse( txtIdUsuario.Text.ToString());
			recomendacion.Descripcion = txtDescripcion.Text.ToString();
			recomendacion.Fecha = DateTime.Parse( txtFecha.Text.ToString());
			if (ViewState["Id"] == null) {
				recomendacion.Alta();
			} else {
				recomendacion.Id = int.Parse(ViewState["Id"].ToString());
				recomendacion.Modificar();
			}
		} catch (Exception ex) {
			LUM.lum.mensaje(ex.Message);
		} finally {
			blanquearCampos();
		}
	}
	protected void grdRecomendacion_RowDeleting(object sender, System.Web.UI.WebControls.GridViewDeleteEventArgs e)
	{
		try {
            Recomendacion recomendacion = new Recomendacion(int.Parse(grdRecomendacion.DataKeys[e.RowIndex].Values["Id"].ToString()));
			recomendacion.Baja();
		} catch (Exception ex) {
			LUM.lum.mensaje(ex.Message);
		}
	}
	protected void grdRecomendacion_SelectedIndexChanged(object sender, System.EventArgs e)
	{
		try {
			preparaModificacion();
			ViewState["Id"] = grdRecomendacion.SelectedDataKey.Values["Id"];
			Recomendacion recomendacion = new Recomendacion(int.Parse(ViewState["Id"].ToString()));
			txtIdPostulacion.Text = recomendacion.IdPostulacion.ToString();
			txtIdUsuario.Text = recomendacion.IdUsuario.ToString();
			txtDescripcion.Text = recomendacion.Descripcion.ToString();
			txtFecha.Text = recomendacion.Fecha.ToString();
		} catch (Exception ex) {
			LUM.lum.mensaje(ex.Message);
		}
	}
	protected void linkNuevo_Click(object sender, System.EventArgs e)
	{
		preparaAlta();
	}
	private void blanquearCampos()
	{
		txtIdPostulacion.Text = "";
		txtIdUsuario.Text = "";
		txtDescripcion.Text = "";
		txtFecha.Text = "";
	}
	private void preparaAlta()
	{
		ViewState.Remove("Id");
		lbl.Text = "Alta de datos";
	}

	private void preparaModificacion()
	{
		lbl.Text = "Modificacion de datos";
	}
}
